/*
 * Copyright (c) 2017 tujia.com. All Rights Reserved.
 */
package com.zhongke.cotrun.common.handler;

import com.google.common.base.Joiner;
import com.zhongke.cotrun.model.pojo.IntSet;
import org.apache.commons.collections.CollectionUtils;

public class IntSetHandler extends BasicTypeHandler<IntSet> {
    protected IntSet fromString(String set) {
        String[] sets = set.split(",");
        IntSet intset = new IntSet();
        if (sets.length == 0) {
            return intset;
        }
        for (String s : sets) {
            intset.add(Integer.valueOf(s));
        }
        return intset;
    }

    protected String toString(IntSet set) {
        if (CollectionUtils.isEmpty(set)) {
            return "";
        }
        return Joiner.on(",").join(set);
    }
}
